package cn.jingzhuan.element.demo.view.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentStatePagerAdapter
import android.util.Log
import cn.jingzhuan.element.demo.view.BaseBindingActivity
import cn.jingzhuan.element.demo.view.fragment.AlbumAudioFragment
import cn.jingzhuan.element.demo.view.fragment.AlbumIntroFragment
import cn.jingzhuan.element.demo.view.model.AudioAlbumItem
import cn.jingzhuan.element.element.R
import cn.jingzhuan.element.element.databinding.ActivityAlbumDetailBinding

class AlbumDetailActivity : BaseBindingActivity<ActivityAlbumDetailBinding>(){

    companion object {
        fun start(context : Context?,id : Int) {
            val intent = Intent(context, AlbumDetailActivity::class.java)
            intent.putExtra("id",id)
            context?.startActivity(intent)
        }
    }

    var fragmentList = mutableListOf<Fragment>()
    val tabs = mutableListOf("简介", "节目")
    lateinit var audioAlbumItem : AudioAlbumItem

    override fun getLayoutId(): Int = R.layout.activity_album_detail

    override fun onDataBind(savedInstanceState: Bundle?, binding: ActivityAlbumDetailBinding) {
        binding.viewToolbar?.title = "专辑详情"
        setUpActionBar(binding.viewToolbar!!.toolbar)
        var id = intent.getIntExtra("id",0)

        audioAlbumItem = AudioAlbumItem(1,"专辑标题","一句话简介","https://img1.doubanio.com/view/subject/m/public/s1505339.jpg",25120391,"投资理论","2018-04-23",2,"炒股人士",10)
        binding.audioAlbum = audioAlbumItem

        Log.i(TAG,"current album id : $id")

        fragmentList.add(AlbumIntroFragment())
        fragmentList.add(AlbumAudioFragment())

        binding.viewPager.adapter = object : FragmentStatePagerAdapter(supportFragmentManager) {

            override fun getItem(position: Int): Fragment = fragmentList[position]

            override fun getCount(): Int = fragmentList.size

            override fun getPageTitle(position: Int): CharSequence? = tabs[position]


        }

        binding.tabLayout.setupWithViewPager(binding.viewPager)
        binding.tabLayout.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{
            override fun onTabReselected(tab: TabLayout.Tab?) {
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }

            override fun onTabSelected(tab: TabLayout.Tab?) {

            }
        })
    }

}